<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="${pageContext.request.contextPath}/js/jquery-1.8.3.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui/layui.js"></script>
</head>
<body>

<div>
    <button class="layui-btn" id="deletes">删除选中</button>
</div>
<table id="demo" lay-filter="myTableFilter"></table>

    <script>
        layui.use(['table','form'], function() {
            var table = layui.table;
            //渲染 table表格
            table.render({
                elem: '#demo'
                , url: '${pageContext.request.contextPath}/log/selectPage' //数据接口
                , page: true //开启分页
                , limit: 5
                , limits: [3, 5, 10]
                , cols: [[ //表头
                      {type:'checkbox',field: 'ids'}
                    , {field: 'logId', title: '编号'}
                    , {field: 'adminUsername', title: '管理员名'}
                    , {field: 'logDate', title: '操作的时间'}
                    , {field: 'logIp', title: 'ip地址'}
                    , {field: 'logContext', title: '操作内容'}
                    , {field: 'logType', title: '操作类型'}
                ]]
            });

            //批量删除 start
            $("#deletes").click(function(){
                var checkStatus = table.checkStatus('demo');
                if(checkStatus.data.length==0){
                    layer.msg('至少选中一行数据');
                    return;
                }
                layer.confirm('确定要删除这么多吗?',function(index){
                    var ids = [];
                    for(var i = 0;i<checkStatus.data.length;i++){

                        ids[i]=checkStatus.data[i].logId;
                    }
                    $.ajax({
                        url:'${pageContext.request.contextPath}/log/deletes',
                        data:'ids='+ids,
                        success:function(result){
                            if(result.flag){
                                layer.close(index);
                                layer.msg("删除成功");
                                table.reload('demo',{
                                    //从第几页开始
                                    page:{curr:1}
                                })
                            }
                        }

                    })
                })
            })
            //批量删除 end

        })
</script>
</body>
</html>
